package source;

import org.apache.flink.api.java.io.TextInputFormat;
import org.apache.flink.core.fs.Path;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.source.FileProcessingMode;

/**
 * readFile Source 读取文件 增量读取
 */
public class ReadFileSourceDemo {

    public static void main(String[] args) throws Exception {

        // 创建Flink程序执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        String path = "C:\\Users\\14461\\Desktop\\flink\\flink_java\\data\\input1\\1.txt";
        // 创建文本文件读取
        TextInputFormat format = new TextInputFormat(new Path(path));
        // 读取文件 如果设置为只读取一次 程序读取一次之后就会停止
        DataStreamSource<String> text = env.readFile(format, path, FileProcessingMode.PROCESS_ONCE, 500);

        // sink
        text.print();

        // 执行
        env.execute("read file");
    }
}
